import { ipcMain } from 'electron';
import { mainWindow } from '../windowControl/mainWindow';
import { WindowType } from '../type';

function getWindow(type: WindowType) {
    const windowMap = {
        [WindowType.mainWindow]: mainWindow,
    };
    return windowMap[type];
}

export default function () {
    // 接收最小化命令
    ipcMain.handle('window-min', function (_, type: WindowType) {
        getWindow(type).minimize();
    });
    // 接收最大化命令
    ipcMain.handle('window-max', function (_, type: WindowType) {
        const w = getWindow(type);
        if (w.isMaximized()) {
            w.restore();
        } else {
            w.maximize();
        }
    });
    // 接收关闭命令
    ipcMain.handle('window-close', function (_, type: WindowType) {
        getWindow(type).hide();
    });
    // 查询窗口是否最大化
    ipcMain.handle('is-max-window', function (_, type: WindowType) {
        return getWindow(type).isMaximized();
    });
}